﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI
{
    public partial class Preview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            string ID = Request["ID"];
            string Token = Request["Token"];
            string Method = Request["Method"];
            string SubName = Request["SubName"];
            string area = HttpContext.Current.Request["area"];
            WeiXin wx = new WeiXin();
            string domain = wx.FindUrl(area, ""); 
            string url = domain + "/Admin/Case/" + Method + ".aspx?From=App&ID=" + ID + "&Token=" + Token + "&SubName=" + SubName;
            string html = GetHtml(url);
            string css = GetHtml(domain + "/css/sheet.css");
            Response.Write(html.Replace("<style>#print", "<style>"+ css + " #print" ));
        }
        public string GetHtml(string url)
        {
            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            string htmlCode = string.Empty;
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                htmlCode = reader.ReadToEnd();                
            }
            return htmlCode;
        }
    }
}